package com.honry.identityaccess.domain.model.identity;

import java.io.Serializable;
import java.util.regex.Pattern;

import com.honry.common.AssertionConcern;

public final class Telephone extends AssertionConcern implements Serializable {

	private static final long serialVersionUID = 1L;
	private String number;
	public Telephone() {
		
	}
	public Telephone(String number) {
		this.setNumber(number);
	}
	public Telephone(Telephone telephone) {
		this(telephone.number);
	}
	public String number(){
		return this.number;
	}
	private void setNumber(String number){
		assertArgumentNotEmpty(number, "不能为空.");
		assertArgumentLength(number, 5,20, "电话号码长度不能超过20");
		this.assertArgumentTrue(
                Pattern.matches("\\d{11}|\\d{3,4}-\\d{6,8}", number),
                "电话号码格式不正确.");
		this.number=number;
	}
	@Override
	public boolean equals(Object object){
		boolean equalsObjects=false;
		if(object!=null&&this.getClass()==object.getClass()){
			Telephone typeObject=(Telephone)object;
			return this.number().equals(typeObject.number());
		}
		return equalsObjects;
	}
	@Override
	public int hashCode(){
		return (35137 * 239) + this.number().hashCode();
	}
	@Override
	public String toString(){
		return "Telephone[number="+this.number()+"]";
	}
}
